<?php
    /*\
     *  Model - oh.framework
     *  --------------------
     *  name: model
     *  sign: 
	 *	date: 
     *  desc: data abstraction for database data
    \*/

	// Interface function   
	function oh_module_images($tokens) {
        global $oh_object_images;
        return $oh_object_images;        
	} 
	
	require_once($oh["path"]."/modules/images/wideimage-10.02.08-lib/WideImage.php");
	
	class oh_class_images { 
		function oh_class_images() {
		}
		function save_from_post($postname,$path,$filename,$manipulate="") {			
			$tmp = $_FILES[$postname]['tmp_name'];
			$inf = pathinfo($_FILES[$postname]['name']);
			$fil = pathinfo($filename);
			$new = $fil['filename'].".".strtolower($inf['extension']);
			if (!$manipulate) {
				if (copy($tmp,$path."/".$new)) {
					return $new;
				} else {
					return false;
				}
			} else {
				$wi = new WideImage();
				$wi = $wi->load($tmp);
				$ma = explode("-",$manipulate);
				if ($ma[0] == "crop") {
					if ($ma[1] == "outer") {
						$wi	->resize($ma[2],$ma[3],"outside")
							->crop("50%-".((int)$ma[2]/2),"50%-".((int)$ma[3]/2),$ma[2],$ma[3])
							->savetofile($path."/".$new);
						return $new;
					}
				} else if ($ma[0] == "resize"){
					$wi	->resize($ma[1],$ma[2])
						->savetofile($path."/".$new);
					return $new;
				}
			}
		}
	}
	global $oh_object_images;
	$oh_object_images = new oh_class_images();
?>
